﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using BLL;
using DAL;
namespace PhongMachTu
{
    public partial class frmHome : Form
    {
        public frmHome()
        {
            InitializeComponent();
        }

        private void đăngKýToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        public TAIKHOAN tk = new TAIKHOAN();
        private void frmHome_Load(object sender, EventArgs e)
        {
            lblUser.Text = MsgBox.tk.HoTen;
            đăngKýToolStripMenuItem1.Visible = false;

            switch (MsgBox.tk.ChucVu)
            {
                case "Bác Sĩ":
                    GUI.DSBenhNhan qd = new GUI.DSBenhNhan();
                    qd.MdiParent = this;
                    báoCáoToolStripMenuItem.Enabled = true;
                    quảnLýToolStripMenuItem.Enabled = true;
                    đăngKýToolStripMenuItem2.Enabled = true;
                    qd.Show();
                    break;
                case "Y Tá":
                    báoCáoToolStripMenuItem.Enabled = false;
                    quảnLýToolStripMenuItem.Enabled = false;
                    đăngKýToolStripMenuItem2.Enabled = false;
                    GUI.DSkhambenh kb = new GUI.DSkhambenh();
                    kb.MdiParent = this;
                    kb.Show();
                    break;
            }
        }

        private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            đăngKýToolStripMenuItem1.Visible = true;
            MsgBox.tk = null;
            lblUser.Text = "Xin chào Khách";
            MsgBox.checkLogin = false;
            GUI.frmDangNhap frm = new GUI.frmDangNhap();
            frm.ShowDialog();
        }

        private void đăngKýToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            GUI.frmDangNhap frm = new GUI.frmDangNhap();
            frm.ShowDialog();
        }

        private void lậpPhiếuKhámBệnhToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.frmQuyDinh qd = new GUI.frmQuyDinh();
            qd.MdiParent = this;
            qd.Show();
        }

        private void quảnLýCáchDùngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.frmQuanLyCachDung cd = new GUI.frmQuanLyCachDung();
            cd.MdiParent = this;
            cd.Show();
        }

        private void quảnLýBệnhNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.DSkhambenh bn = new GUI.DSkhambenh();
            bn.MdiParent = this;
            bn.Show();
        }

        private void quảnLýĐơnVịToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.frmquanliloaibenh lb = new GUI.frmquanliloaibenh();
            lb.MdiParent = this;
            lb.Show();
        }

        private void quảnLýThuốcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.QLthuoc qlt = new GUI.QLthuoc();
            qlt.MdiParent = this;
            qlt.Show();
        }

        private void quảnLýĐơnVịToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            GUI.Qldonvi qldv = new GUI.Qldonvi();
            qldv.MdiParent = this;
            qldv.Show();
        }

        private void báoCáoToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        public void phiếuKhámBệnhToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void giúpĐỡToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (File.Exists(Application.StartupPath + "\\thongtin.doc") == true)
            {
                System.Diagnostics.Process.Start(Application.StartupPath + "\\thongtin.doc");
            }
            else
            {
                MessageBox.Show("File không tồng tại.");
            }
        }

        private void frmHome_MdiChildActivate(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild == null)
                tabForms.Visible = false; // If no any child form, hide tabControl
            else
            {
                this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized

                // If child form is new and no has tabPage, create new tabPage
                if (this.ActiveMdiChild.Tag == null)
                {
                    // Add a tabPage to tabControl with child form caption
                    TabPage tp = new TabPage(this.ActiveMdiChild.Text);
                    tp.Tag = this.ActiveMdiChild;
                    tp.Parent = tabForms;
                    tabForms.SelectedTab = tp;

                    this.ActiveMdiChild.Tag = tp;
                    this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
                }

                if (!tabForms.Visible) tabForms.Visible = true;
            }
        }

        private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
        {
            ((sender as Form).Tag as TabPage).Dispose();
        }

        private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
                (tabForms.SelectedTab.Tag as Form).Select();
        }

        private void danhSáchBênhNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.DSkhambenh ds = new GUI.DSkhambenh();

            ds.MdiParent = this;
            ds.Show();
        }

        private void âToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(tk.HoTen);
        }

        private void doanhThuTheoNgàyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.frmDoanhThuTheoNgay ds = new GUI.frmDoanhThuTheoNgay();

            ds.MdiParent = this;
            ds.Show();
        }

        private void báoCáoSửDụngThuốcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GUI.frmBaoCaoThuoc ds = new GUI.frmBaoCaoThuoc();

            ds.MdiParent = this;
            ds.Show();
        }

        private void đăngKýToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            GUI.DangKi dk = new GUI.DangKi();
            dk.ShowDialog();
        }
    }
}
